import {BaseThree} from "../base/BaseThree";
import * as THREE from 'three'

export class AddTest extends BaseThree {
  constructor( view, pos) {
    super(view,pos)
  }
  setup(pos) {
    pos = this.toRenderCoordinates(pos);
    let {scene} = this;
    var SEPARATION = 100, AMOUNTX = 50, AMOUNTY = 50;
    var numParticles = AMOUNTX * AMOUNTY;
    var positions = new Float32Array( numParticles * 3 );
    var scales = new Float32Array( numParticles );
    var i = 0, j = 0;
    for ( var ix = 0; ix < AMOUNTX; ix ++ ) {
      for ( var iy = 0; iy < AMOUNTY; iy ++ ) {
        positions[ i ] = pos[0] + ix * SEPARATION - ( ( AMOUNTX * SEPARATION ) / 2 ); // x
        positions[ i + 1 ] = pos[1] + iy * SEPARATION - ( ( AMOUNTY * SEPARATION ) / 2 ); // y
        positions[ i + 2 ] = pos[2] ; // z
        scales[ j ] = 1;
        i += 3;
        j ++;
      }
    }
    var geometry = new THREE.BufferGeometry();
    geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
    geometry.addAttribute( 'scale', new THREE.BufferAttribute( scales, 1 ) );
    点渲染模式
    var material = new THREE.PointsMaterial({
      color: 0xffff00,
      size: 10.0 //点对象像素尺寸
    }); //材质对象
        var particles = new THREE.Points( geometry, material );
    // 线条渲染模式
    // var material=new THREE.LineBasicMaterial({
    //   color:0xff0000 //线条颜色
    // });//材质对象
    // var particles = new THREE.Line( geometry, material );

   // 三角面(网格)渲染模式
   //  var material = new THREE.MeshBasicMaterial({
   //    color: 0x0000ff, //三角面颜色
   //    side: THREE.DoubleSide //两面可见
   //  }); //材质对象
   //  var particles = new THREE.Mesh(geometry, material); //网格模型对象Mesh
   //  var material = new THREE.MeshLambertMaterial({
   //    color: 0xff0000
   //  }); //材质对象Material
   //  var particles = new THREE.Mesh(geometry, material); //网格模型对象Mesh
    scene.add( particles );
    this.initRender();
  }

}

